package com.yvan.leto.server.controller;

import com.yvan.leto.server.config.YvanSecurityProperties;
import com.yvan.leto.server.security.JwtHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

@RestController
public class RootController {

    @Autowired
    private YvanSecurityProperties securityProperties;


    @RequestMapping(value = {"/", "/index.htm"}, method = RequestMethod.GET)
    public ModelAndView index() {

        if (JwtHelper.verify(securityProperties.getSalt())) {
            return new ModelAndView(new RedirectView("/projects"));
        }

        return new ModelAndView(new RedirectView("/user/login.htm"));
    }
}
